import { getArchivesList, getArchivesListId } from "@/services";
const state = {
  archivesList: [],
  archivesListId: [],
  DetailHeight:0
};

const mutations = {
  ArchivesList(state, data) {
    state.archivesList = data;
  },
  ArchivesListId(state, data) {
    state.archivesListId = data;
  },
  ArchivesLikes(state,payload){
    let i=state.archivesList.findIndex(item=>item.id===payload);
    if(i!=-1)
    {
      //开关
      state.archivesListId.isply=!state.archivesListId.isply;
      //个数加减
      state.archivesListId.isply?state.archivesListId.likes+=1:state.archivesListId.likes-=1;
    }
  },
  ArchivesHeight(state, data){
    state.DetailHeight = data*1+140
  }
};

const actions = {
  async getArchivesList({ commit }) {
    let result = await getArchivesList();
    console.log(result);
    commit("ArchivesList", result);
  },     

  async getArchivesListId({ commit }, payload) {
    let result = await getArchivesListId(payload);
    commit("ArchivesListId", result);
  }, 
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};